<template>
    <div class="goodsContent">
        <!--左侧菜单-->
        <ul class="menu">
            <li v-for="(item, index) in goods" :key="item.name">
                <a :href="`#${index}`"> {{ item.name }}</a>
            </li>
        </ul>
        <!-- 右侧内容列表 -->
        <ol class="list">
            <li v-for="(item, index) in goods" :key="item.name">
                <p :id="index">{{ item.name }}</p>
                <ul class="info">
                    <li v-for="food in item.foods" :key="food.name">
                        <div class="box">
                            <div class="pic">
                                <img :src="food.image" alt="" />
                            </div>
                            <div class="title">
                                <h4>{{ food.name }}</h4>
                                <p> {{ food.description }}</p>
                                <p>月售{{ food.sellCount }}份 好评率{{ food.rating }}%</p>
                                <p>
                                    <span>￥{{ food.price }}</span>
                                    <span v-show="food.oldPrice">￥{{ food.oldPrice }}</span>
                                </p>
                            </div>
                            <!-- 公共组件Btns :item是操作的food对象，type方便判断是否需要定位样式 -->
                            <Btns :item="food" type="0"></Btns>
                        </div>
                    </li>
                </ul>
            </li>
            <li style="text-align: center;">已经到底了哟~</li>
        </ol>
    </div>
    <div class="shopCar" @click="showCar">
        <img :src="img" alt="" />
        <p>￥{{ getPrice }}</p>
        <p>另需配送费4元</p>
        <p>￥20元起送</p>
    </div>
</template>
<script>
import { mapState, mapActions } from 'vuex'
import Btns from './Btns.vue'
export default {
    components: {
        Btns,
    },
    created() {
        this.getGoods();

    },
    computed: {
        ...mapState(['goods', 'price', 'carList', 'img']),
        // 总价
        getPrice() {
            let num = 0;
            this.carList.forEach((item) => {
                num += item.price * item.count;
            })
            return num;
        }
    },
    methods: {
        ...mapActions(['getGoods']),
        showCar() {
            this.$store.commit('showCar');
        },

    },

}
</script>

<style scoped>
.goodsContent {
    display: flex;
    height: 100%;
}

.goodsContent .menu {
    width: 26.667vw;
    height: 70vh;
    overflow-y: scroll;
    text-align: center;
}

.goodsContent>.menu>li {
    padding: 14px 14px 0 14px;
    height: 42px;
    background: #f3f5f7;
    font-size: 3.2vw;
    line-height: 3.733vw;
    border-bottom: 0.133vw solid rgba(7, 17, 27, 0.1);
}

.goodsContent>.menu>li>a {
    color: black;
}

.goodsContent>.menu>li:hover {
    background-color: white;
    border-top: none;
    border-bottom: none;
}


.goodsContent>.menu>li:nth-child(2)::before {
    content: '特';
    font-size: 2.667vw;
    color: white;
    background: rgb(48, 192, 48);
    padding: 0.133vw 0.533vw;
    border-radius: 0.533vw;
    font-weight: bold;
    margin-right: 0.533vw;
}

.list {
    flex: 1;
    height: 62vh;
    overflow-y: scroll;
}

.list li p:nth-child(1) {
    border-left: 4px #d9dde1 solid;
    background: #f3f5f7;
    height: 26px;
    line-height: 26px;
    padding-left: 12px;
    color: rgb(147, 153, 159);
    font-weight: 400;
    font-size: 12px;
}

.list .info li {
    padding: 0 18px;
    position: relative;
}

.list .info li .box {
    display: flex;
    padding: 18px 0;
    border-bottom: 0.133vw rgba(1, 17, 27, 0.1) solid;
}

.list .info li .box .pic img {
    width: 90px;
}


/* title部分 */
.list .info li .box .title {
    padding-left: 10px;
}

.list .info li .box .title h4 {
    font-size: 3.733vw;
    color: rgb(7, 17, 27);
    line-height: 3.733vw;
}

.list .info li .box .title p:nth-child(2),
.list .info li .box .title p:nth-child(3) {
    font-size: 2.667vw;
    color: rgb(147, 153, 157);
    line-height: 2.667vw;
    padding: 2.13vw 0vw;
}

.list .info li .box .title p:nth-child(4)>span:nth-child(1) {
    font-size: 3.733vw;
    color: red;
    line-height: 6.4vw;
    font-weight: 700;

}

.list .info li .box .title p:nth-child(4)>span:nth-child(2) {
    font-size: 2.667vw;
    color: rgb(147, 153, 159);
    line-height: 6.4vw;
    font-weight: 700;
    text-decoration: line-through;

}

.shopCar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #141d27;
    height: 50px;
    z-index: 200;
    color: rgba(255, 255, 255, 0.4);
    display: flex;
    justify-content: space-between;
}

.shopCar img {
    width: 15.467vw;
    height: 13.333vw;
    position: absolute;
    bottom: 2.667vw;
    left: 4.8vw
}

.shopCar>p:nth-child(2) {
    margin-left: 24vw;
    line-height: 8vw;
    font-size: 5.333vw;
    font-weight: 700;
    padding-top: 2.667vw
}

.shopCar>p:nth-child(3) {
    line-height: 8vw;
    font-size: 3.733vw;
    font-weight: 700;
    padding-top: 2.667vw;
    margin-left: 4vw;

}

.shopCar>p:nth-child(4) {
    width: 28vw;
    line-height: 8vw;
    font-size: 3.2vw;
    font-weight: 700;
    padding-top: 2.667vw;
    margin-left: 4vw;
    text-align: center;
    background: rgba(255, 255, 255, 0.2);

}
</style>